import request from '../utils/request'

export function getDocumentsInfo(databaseName, collectionName) {
    return request({
        url: 'getDocumentsInfo',
        method: 'post',
        data: {
            databaseName: databaseName,
            collectionName: collectionName,
        }
    })
}

export function getDocumentsInfoList(databaseName, collectionName, filterFrom) {
    return request({
        url: 'getDocumentsInfoList',
        method: 'post',
        data: {
            databaseName: databaseName,
            collectionName: collectionName,
            currentPage: filterFrom.currentPage,
            pageSize: filterFrom.pageSize,
            skip: filterFrom.skip,
            sorts: filterFrom.sorts,
            projects: filterFrom.projects,
            filters: filterFrom.filters,
            collections: filterFrom.collections,
        }
    })
}

export function insertDocument(documents, databaseName, collectionName, connectionId) {
    return request({
        url: 'insertDocument',
        method: "post",
        headers: {
            'Content-Type': 'application/json'
        },
        data: {
            documents: documents,
            databaseName: databaseName,
            collectionName: collectionName,
            connectionId: connectionId
        }
    })
}

export function dropDocument(documents, databaseName, collectionName, connectionId) {
    return request({
        url: 'dropDocument',
        method: "post",
        headers: {
            'Content-Type': 'application/json'
        },
        data: {
            documents: documents,
            databaseName: databaseName,
            collectionName: collectionName,
            connectionId: connectionId
        }
    })
}

export function updateDocument(documents, databaseName, collectionName, connectionId) {
    return request({
        url: 'updateDocument',
        method: "post",
        headers: {
            'Content-Type': 'application/json'
        },
        data: {
            documents: documents,
            databaseName: databaseName,
            collectionName: collectionName,
            connectionId: connectionId
        }
    })
}